﻿using System;
using System.Collections.Generic;
using System.Text;
using Common;
using UnityEngine;


public class ActionModule : ModuleBase, IActionModule
{
    private SoulManager soul;
    public ActionModule()
    {
        AppInterface.ActionModule = this as IActionModule;
        soul = new SoulManager(this);
    }
    public override void Update()
    {
        deleteIndex = -1;
        for (int i = 0; i < actionList.Count; i++)
        {
            tmpBase = actionList[i];
            if (tmpBase.End) deleteIndex = i;
            else tmpBase.Update();
        }
        if (deleteIndex > -1)
        {
            actionList.RemoveAt(deleteIndex);
        }
        soul.Update();
    }
    public override void FixedUpdate()
    {
        for (int i = 0; i < actionList.Count; i++)
        {
            tmpBase = actionList[i];
            if (!tmpBase.End) tmpBase.LateUpdate();
        }
        soul.FixedUpdate();
    }
    public override void LateUpdate()
    {
        for (int i = 0; i < actionList.Count; i++)
        {
            tmpBase = actionList[i];
            if (!tmpBase.End) tmpBase.LateUpdate();
        }
        soul.LateUpdate();
    }

    #region IActionModule Members
    private List<IBase> actionList = new List<IBase>();
    private IBase tmpBase;
    private int deleteIndex = -1;
    public void RegisterAction(IBase action)
    {
        actionList.Add(action);
    }

    public void RegisterEffect(IBase effect)
    {
        actionList.Add(effect);
    }
    public void AddSoul(Vector3 v)
    {
        soul.AddSoul(v);
    }

    public void SuckSoul(Vector3 v)
    {
        soul.SuckSoul(v);
    }

    #endregion
}

